oo::class create ActionCollection {
    variable ActionTasks PluginFactory RenamedPadWidget Plugins

    constructor {pluginFactory plugins} {
        set ActionTasks [ActionTasks new]
        set PluginFactory $pluginFactory
        set RenamedPadWidget [eval set [info object namespace $PluginFactory]::RenamedPadWidget]
        set Plugins $plugins
        my generatePlugin
    }

    method generatePlugin {} {
        foreach p $Plugins {
            # set pp [$PluginFactory get $p]
            # puts "--$p -> $pp--"
            my installEventHandles [$PluginFactory get $p]; # $pp
        }
    }

    method installEventHandles {plugin} {
        foreach eh [$plugin getPluginEvents] {
            foreach {e h} $eh {}
            $ActionTasks appendTask $e [list $plugin $h]
        }
    }

    method insert {index content args} {
        set index [$RenamedPadWidget index $index]
        $ActionTasks runTasks afterInsert $index $content
        $ActionTasks runTasks beforeInsert $index $content
    }

    method delete {from args} {
        if {$args != {}} {
            set to [$RenamedPadWidget index [lindex $args 0]]
        } else {
            set to {}
        }
        set from [$RenamedPadWidget index $from]
        $ActionTasks runTasks beforeDelete $from $to
        $ActionTasks runTasks afterDelete $from $to
    }

    method replace {from to content args} {
        set from [$RenamedPadWidget index $from]
        set to [$RenamedPadWidget index $to]

        $ActionTasks runTasks beforeReplace $from $to $content
        $ActionTasks runTasks afterReplace $from $to $content
    }

    method mark {type args} {
        if {$type == {set} && [lindex $args 0] == {insert}} {
            set index [lindex $args 1]
            $ActionTasks runTasks beforeMarkSetInsert
            $ActionTasks runTasks afterMarkSetInsert
        }
    }

    method see {index} {
        if {$index == {insert}} {
            $ActionTasks runTasks beforeSee $index
            $ActionTasks runTasks afterSee $index
        }
    }

    destructor {
        $ActionTasks destroy
        $PluginFactory destroy
    }
}